package com.breeze.leetcode.easy;

/**
 * @url <a href="https://leetcode.cn/problems/element-appearing-more-than-25-in-sorted-array">1287. 有序数组中出现次数超过25%的元素</a>
 * @author yangzh
 * @date 2025/2/17
 */
public class T1287 {

    public static void main(String[] args) {
        int[] arr = { 1,2,2,6,6,6,6,7,10 };
        T1287 solution = new T1287();
        int result = solution.findSpecialInteger(arr);
        System.out.println(result);
    }

    public int findSpecialInteger(int[] arr) {
        int[] temp = new int[100001];
        int result = 0, size = arr.length / 4;

        for (int i : arr) {
            temp[i]++;
            if (temp[i] > temp[result]) {
                result = i;
            }

            if (temp[result] > size) {
                return result;
            }
        }

        return result;
    }
}
